#!/bin/bash

# init variable
pipeline_id=971024
date=20230920

clang_linux_x86_64_tar="clang-dev-linux-x86_64.tar.bz2"
clang_darwin_arm64_tar="clang-dev-darwin-arm64.tar.bz2"
clang_darwin_x86_64_tar="clang-dev-darwin-x86_64.tar.bz2"
clang_windows_x86_64_tar="clang-dev-windows-x86_64.tar.bz2"
libcxx_ndk_linux_x86_64_tar="libcxx-ndk-dev-linux-x86_64.tar.bz2"
libcxx_ndk_darwin_x86_64_tar="libcxx-ndk-dev-darwin-x86_64.tar.bz2"
libcxx_ndk_darwin_arm64_tar="libcxx-ndk-dev-darwin-arm64.tar.bz2"
libcxx_ndk_windows_x86_64_tar="libcxx-ndk-dev-windows-x86_64.tar.bz2"

clang_linux_x86_64="clang_linux-x86_64-${pipeline_id}-${date}"
clang_darwin_arm64="clang_darwin-arm64-${pipeline_id}-${date}"
clang_darwin_x86_64="clang_darwin-x86_64-${pipeline_id}-${date}"
clang_windows_x86_64="clang_windows-x86_64-${pipeline_id}-${date}"
libcxx_ndk_linux_x86_64="libcxx-ndk_linux-x86_64-${pipeline_id}-${date}"
libcxx_ndk_darwin_x86_64="libcxx-ndk_darwin-x86_64-${pipeline_id}-${date}"
libcxx_ndk_darwin_arm64="libcxx-ndk_darwin-arm64-${pipeline_id}-${date}"
libcxx_ndk_windows_x86_64="libcxx-ndk_windows-x86_64-${pipeline_id}-${date}"

libcxx_ndk_linux_x86_64_pre="libcxx-ndk_pre"

# decompress file and rename
tar -xvf ${clang_linux_x86_64_tar}
mv clang-dev ${clang_linux_x86_64}
tar -xvf ${clang_darwin_arm64_tar}
mv clang-dev ${clang_darwin_arm64}
tar -xvf ${clang_darwin_x86_64_tar}
mv clang-dev ${clang_darwin_x86_64}
tar -xvf ${clang_windows_x86_64_tar}
mv clang-dev ${clang_windows_x86_64}
tar -xvf ${libcxx_ndk_linux_x86_64_tar}
mv libcxx-ndk ${libcxx_ndk_linux_x86_64}
tar -xvf ${libcxx_ndk_darwin_x86_64_tar}
mv libcxx-ndk ${libcxx_ndk_darwin_x86_64}
tar -xvf ${libcxx_ndk_darwin_arm64_tar}
mv libcxx-ndk ${libcxx_ndk_darwin_arm64}
tar -xvf ${libcxx_ndk_windows_x86_64_tar}
mv libcxx-ndk ${libcxx_ndk_windows_x86_64}

#clang-dev-darwin-arm64
cp -rf ${clang_linux_x86_64}/lib/aarch64-linux-ohos ${clang_darwin_arm64}/lib
cp -rf ${clang_linux_x86_64}/lib/arm-liteos-ohos ${clang_darwin_arm64}/lib
cp -rf ${clang_linux_x86_64}/include/libcxx-ohos ${clang_darwin_arm64}/include
cp -rf ${clang_linux_x86_64}/lib/arm-linux-ohos ${clang_darwin_arm64}/lib
cp -rf ${clang_linux_x86_64}/lib/x86_64-linux-ohos ${clang_darwin_arm64}/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/bin ${clang_darwin_arm64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/fuzzer ${clang_darwin_arm64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/share ${clang_darwin_arm64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/sanitizer ${clang_darwin_arm64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib/aarch64-linux-ohos ${clang_darwin_arm64}/lib/clang/15.0.4/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib/arm-liteos-ohos ${clang_darwin_arm64}/lib/clang/15.0.4/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib/arm-linux-ohos ${clang_darwin_arm64}/lib/clang/15.0.4/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib/x86_64-linux-ohos ${clang_darwin_arm64}/lib/clang/15.0.4/lib

#clang-dev-darwin-x86_64
cp -rf ${clang_linux_x86_64}/lib/aarch64-linux-ohos ${clang_darwin_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/arm-liteos-ohos ${clang_darwin_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/arm-linux-ohos ${clang_darwin_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/x86_64-linux-ohos ${clang_darwin_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/bin ${clang_darwin_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/share ${clang_darwin_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib ${clang_darwin_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/profile ${clang_darwin_x86_64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/fuzzer ${clang_darwin_x86_64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/sanitizer ${clang_darwin_x86_64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/include/libcxx-ohos ${clang_darwin_x86_64}/include

#clang-dev-windows-x86_64
cp -rf ${clang_linux_x86_64}/include/libcxx-ohos ${clang_windows_x86_64}/include
cp -rf ${clang_linux_x86_64}/lib/aarch64-linux-ohos ${clang_windows_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/arm-liteos-ohos ${clang_windows_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/arm-linux-ohos ${clang_windows_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/x86_64-linux-ohos ${clang_windows_x86_64}/lib
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/bin ${clang_windows_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/share ${clang_windows_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/lib ${clang_windows_x86_64}/lib/clang/15.0.4
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/profile ${clang_windows_x86_64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/fuzzer ${clang_windows_x86_64}/lib/clang/15.0.4/include
cp -rf ${clang_linux_x86_64}/lib/clang/15.0.4/include/sanitizer ${clang_windows_x86_64}/lib/clang/15.0.4/include

#${libcxx_ndk_darwin_x86_64}
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/aarch64-linux-hos/ ${libcxx_ndk_darwin_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/arm-linux-hos/ ${libcxx_ndk_darwin_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/x86_64-linux-hos/ ${libcxx_ndk_darwin_x86_64}/lib

#${libcxx_ndk_windows_x86_64}
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/aarch64-linux-hos/ ${libcxx_ndk_windows_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/arm-linux-hos/ ${libcxx_ndk_windows_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/x86_64-linux-hos/ ${libcxx_ndk_windows_x86_64}/lib

#${libcxx_ndk_darwin_arm64}
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/aarch64-linux-hos/ ${libcxx_ndk_darwin_arm64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/arm-linux-hos/ ${libcxx_ndk_darwin_arm64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/x86_64-linux-hos/ ${libcxx_ndk_darwin_arm64}/lib

#${libcxx_ndk_linux_x86_64}
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/aarch64-linux-hos/ ${libcxx_ndk_linux_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/arm-linux-hos/ ${libcxx_ndk_linux_x86_64}/lib
cp -rf ${libcxx_ndk_linux_x86_64_pre}/lib/x86_64-linux-hos/ ${libcxx_ndk_linux_x86_64}/lib

#archive
mkdir target_location
tar jcvf target_location/${clang_linux_x86_64}.tar.bz2 ${clang_linux_x86_64}
tar jcvf target_location/${clang_darwin_x86_64}.tar.bz2 ${clang_darwin_x86_64}
tar jcvf target_location/${clang_darwin_arm64}.tar.bz2 ${clang_darwin_arm64}
tar jcvf target_location/${clang_windows_x86_64}.tar.bz2 ${clang_windows_x86_64}
tar jcvf target_location/${libcxx_ndk_linux_x86_64}.tar.bz2 ${libcxx_ndk_linux_x86_64}
tar jcvf target_location/${libcxx_ndk_darwin_x86_64}.tar.bz2 ${libcxx_ndk_darwin_x86_64}
tar jcvf target_location/${libcxx_ndk_darwin_arm64}.tar.bz2 ${libcxx_ndk_darwin_arm64}
tar jcvf target_location/${libcxx_ndk_windows_x86_64}.tar.bz2 ${libcxx_ndk_windows_x86_64}